package com.example.workassignback.Mapper;

import com.example.workassignback.POJO.Doctor;
import com.example.workassignback.POJO.Item;
import com.example.workassignback.POJO.Patient;
import com.example.workassignback.POJO.ProcessItem;
import org.apache.ibatis.annotations.*;

import javax.swing.*;
import java.util.List;
import java.util.Map;

/**
 * @Auther: Lai Wenhao
 * @Date: 2024/6/1 11:27
 **/
@Mapper
public interface DoctorMapper {
    @Select("SELECT\n" +
            "    u.uId,\n" +
            "    u.password,\n" +
            "    u.name,\n" +
            "    u.gender,\n" +
            "    u.cardId,\n" +
            "    u.birthday,\n" +
            "    u.phone,\n" +
            "    u.homeAddress,\n" +
            "    d.dId\n" +
            "FROM\n" +
            "    Users u\n" +
            "        JOIN\n" +
            "    Doctors d ON u.uId = d.uId\n" +
            "WHERE\n" +
            "    u.uId = #{id}")
    public Doctor getInfo(String id);

    @Select("SELECT\n" +
            "    Items.iId,\n" +
            "    Items.iName,\n" +
            "    Items.finishTime\n" +
            "FROM\n" +
            "    Doctor_Item\n" +
            "        JOIN\n" +
            "    Items ON Doctor_Item.iId = Items.iId\n" +
            "WHERE\n" +
            "        Doctor_Item.dId = #{dId};")
    public List<Item> getItemFromDoctorId(String dId);

    @Select("SELECT \n" +
            "    Patients.pId,\n" +
            "    Users.name,\n" +
            "    Users.gender,\n" +
            "    Users.cardId,\n" +
            "    Users.birthday,\n" +
            "    Users.phone,\n" +
            "    Users.homeAddress,\n" +
            "    Patients.contactPerson,\n" +
            "    Patients.contactPhone,\n" +
            "    Patients.relation\n" +
            "FROM \n" +
            "    Patients\n" +
            "JOIN \n" +
            "    Users ON Patients.uId = Users.uId\n" +
            "WHERE \n" +
            "    Users.cardId = #{cardId};\n")
    public Patient getPainterByCardId(String cardId);

    @Select("SELECT \n" +
            "    Patients.pId,\n" +
            "    Users.name,\n" +
            "    Users.gender,\n" +
            "    Users.cardId,\n" +
            "    Users.birthday,\n" +
            "    Users.phone,\n" +
            "    Users.homeAddress,\n" +
            "    Patients.contactPerson,\n" +
            "    Patients.contactPhone,\n" +
            "    Patients.relation\n" +
            "FROM \n" +
            "    Patients\n" +
            "JOIN \n" +
            "    Users ON Patients.uId = Users.uId\n" +
            "WHERE \n" +
            "    Users.name = #{name};\n")
    public List<Patient> getPainterByName(String name);


    @Select("SELECT p.prId,\n" +
            "       p.startTime,\n" +
            "       u.name AS patientName,\n" +
            "       i.iId,\n" +
            "       i.iName,\n" +
            "       i.finishTime,\n" +
            "       pi.therapyAddress,\n" +
            "       pi.intervalTime,\n" +
            "       pi.num,\n" +
            "       pi.status\n" +

            "FROM Process_Items pi\n" +
            "         JOIN\n" +
            "     Processes p ON pi.prId = p.prId\n" +
            "         JOIN\n" +
            "     Patients pa ON p.pId = pa.pId\n" +
            "         JOIN\n" +
            "     Users u ON pa.uId = u.uId\n" +
            "         JOIN\n" +
            "     Items i ON pi.iId = i.iId\n" +
            "WHERE pi.dId = #{dId}\n" +
            "  AND pi.status = #{status};")
    public List<Map<String,Object>> GetBeginItemsByStatus(String dId, String status);

    @Select("select did from Doctors where uId=#{uId};")
    public String getDoctorIdByUserId(String uId);

    @Update("update Users set uId=#{uId},birthday=#{birthday},phone=#{phone},password=#{password},homeAddress=#{homeAddress} where uId=#{uId}")
    public Integer modifyInfo(Doctor doctor);
}
